package com.yuanfeng.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanfeng.business.entity.ShopBaseEntity;
import com.yuanfeng.business.entity.ShopContractEntity;
import com.yuanfeng.business.mapper.ShopBaseMapper;
import com.yuanfeng.business.mapper.ShopContractMapper;
import com.yuanfeng.business.service.ShopContractService;
import com.yuanfeng.commoms.dto.shop.ShopContractDTO;
import com.yuanfeng.commoms.exception.BizCodeEnume;
import com.yuanfeng.commoms.util.ResponseResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 *
 */
@Service
public class ShopContractServiceImpl extends ServiceImpl<ShopContractMapper, ShopContractEntity>
    implements ShopContractService{

    @Resource
    private ShopBaseMapper shopBaseMapper;
    @Override
    public ResponseResult getShopContract(Integer shopId) {
        try {
            ShopContractDTO contract = this.baseMapper.queryShopContract(shopId);
            ShopBaseEntity shopBase = shopBaseMapper.selectOne(new LambdaQueryWrapper<ShopBaseEntity>()
                    .select(ShopBaseEntity::getShopLogo).eq(ShopBaseEntity::getShopId, shopId));
            contract.setLogo(shopBase.getShopLogo());
            return ResponseResult.success(contract);
        } catch (Exception e) {
            return ResponseResult.fail(BizCodeEnume.NO_CONTRACT_FOUND.getCode(), BizCodeEnume.NO_CONTRACT_FOUND.getMsg());
        }
    }
}




